#include "../StdInc.h"
#include "InnerImpl.h"

#include<boost/date_time/gregorian/greg_month.hpp>
#include<boost/date_time/gregorian/gregorian.hpp>

using namespace boost;
using namespace boost::gregorian;

namespace GSTrader
{
	namespace TradeStrategy
	{
		CInnerImpl::CInnerImpl(CFramework* pFramework) : m_pFramework(pFramework)
		{
		}


		CInnerImpl::~CInnerImpl()
		{
		}

		int CInnerImpl::GetExpireDate(CInstrument* pInstrument)
		{
			if (pInstrument == NULL)
				return -1;

			if (pInstrument->m_strMaturity.empty() || pInstrument->m_strMaturity.length() != 8)
				return -1;

			int nYear, nMonth, nDay;
			if (!ConvertStringToDate(pInstrument->m_strMaturity, nYear, nMonth, nDay))
				return -1;

			date today = day_clock::local_day();
			date expireDate(nYear, nMonth, nDay);

			date_duration duration = expireDate - today;
			return duration.days();
		}
	}
}